package cn.edu.ctbu.sbadmin.lablog.service;

import cn.edu.ctbu.sbadmin.common.core.AbstractService;
import cn.edu.ctbu.sbadmin.common.utils.MQuery;
import cn.edu.ctbu.sbadmin.common.utils.MQueryHelper;
import cn.edu.ctbu.sbadmin.lablog.dao.DimClassDAO;
import cn.edu.ctbu.sbadmin.lablog.domain.DimClassDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 课程班级服务类
 */
@Service
@Transactional
public class DimClassService extends AbstractService<DimClassDO> {

    @Autowired
    private DimClassDAO dimClassDAO;

    /**
     * 通用查询，返回视图
     * @param mQuery
     * @return
     */
    public List<DimClassDO> listView(MQuery mQuery){
        return dimClassDAO.listView(mQuery);
    }

    /**
     * 通用查询，返回数量
     * @param mQuery
     * @return
     */
    public int countView(MQuery mQuery){
        return dimClassDAO.countView(mQuery);
    }


    /**\
     * 根据当前的id来取对应的DO，是完整的DO
     * @param id
     * @return
     * @throws Exception
     */
    public DimClassDO getViewById(Long id) throws Exception{
        MQuery mQuery= MQueryHelper.GenQuery("dim_class.id="+id+"^:=",10,0,"","",true);
        List<DimClassDO> dimClassDOS=dimClassDAO.listView(mQuery);
        if(dimClassDOS.size()>0){
            return dimClassDOS.get(0);
        }
        return null;
    }

}
